<?php

namespace Pocker\PockerBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use ElephantIO\Client,
    ElephantIO\Engine\SocketIO\Version1X;
use Pocker\AdminBundle\Controller\AdminController as BaseController;

class DefaultController extends BaseController
{
    public function helloAction($name)
    {
        return $this->render('PockerBundle:Default:index.html.twig', array('name' => $name));
    }
	
	public function testAction()
    {
    	
    	$symbol = '{{{suit.symbol}}}';
		
        return $this->render('PockerBundle:Pocker:index.html.twig', array('symbol' => $symbol, 'name' => '{{suit.name}}'));
    }
	
	public function indexAction()
    {
    	$response = parent::loginAction();
		// $url = $this -> generateUrl("pocker_admin_login");
		// echo "<a href='{$url}'>{$url}</a>";
		// var_dump($response);die;
        // ... do custom stuff
        return $response;
    	echo 'Index 23';
    	die;
    	$symbol = '{{{suit.symbol}}}';
		
        return $this->render('PockerBundle:Pocker:index.html.twig', array('symbol' => $symbol, 'name' => '{{suit.name}}'));
    }
	
	public function sendAction(){
		$client = new Client(new Version1X('http://localhost:3000'));
		$client->initialize();
		// $r = $client->read();
		$request = $this -> getRequest();
		
		$suit = rand(0, 3);
		$rank = rand(0, 12);
		$aryCardData = array('SUIT' => $suit, 'RANK' => $rank, 'view' => $request -> get('view'));
		
		$client -> emit('broadcast', array('message' => 'bocbai2', 'cardData' => $aryCardData, 'socketidto' => $request -> get('target'), 'socketidfrom' => $request -> get('from')));
		echo json_encode($aryCardData);
		die;
	}
}
